//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "ColorArcForm.h"
#include "MainForm.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TCAF *CAF;
//---------------------------------------------------------------------------
__fastcall TCAF::TCAF(TComponent* Owner) : TForm(Owner) {}
//---------------------------------------------------------------------------
void __fastcall TCAF::FormShow(TObject *Sender) {
	color tmp;
	for (int i = 0; i < res.size(); i++) {
		delete res[i].img;
		delete res[i].se;
	}
	res.clear();
	vector <rule> r = MF->cpn->getRules();
	for (int i = 0; i < CF->res.size(); i++) {
		tmp.img = new TImage(this);
		tmp.img->Height = 20;
		tmp.img->Width = 50;
		tmp.img->Tag = CF->res[i].index;
		tmp.img->Canvas->Brush->Color = mark_colors[CF->res[i].index];
		tmp.img->Canvas->Rectangle(0, 0, 50, 20);
		tmp.img->Top = i * 25 + 10;
		tmp.img->Left = 10;
		tmp.img->Parent = SB;
		tmp.img->Show();
		tmp.se = new TCSpinEdit(this);
		tmp.se->Parent = SB;
		tmp.se->Left = 80;
		tmp.se->Top = i * 25 + 10;
		tmp.se->Width = 50;
		for (int j = 0; j < r.size(); j++)
			if (tmp.img->Tag == r[j].color) {
				tmp.se->Value = r[j].markcount;
				break;
			}
		tmp.se->Show();
		res.push_back(tmp);
	}
}
//---------------------------------------------------------------------------
void __fastcall TCAF::OkBClick(TObject *Sender) {
	rule tmp;
	rules.clear();
	for (int i = 0; i < res.size(); i++)
		if (res[i].se->Value != 0) {
			tmp.color = res[i].img->Tag;
			tmp.markcount = res[i].se->Value;
			rules.push_back(tmp);
		}
	MF->cpn->setRules(rules);
	MF->cpn->refrash();
	Close();
}
//---------------------------------------------------------------------------
